<?php

/**
 * 夏日葵电商系统
 * http://www.xiarikui.com
 */

namespace Admin\Controller;

use Think\Page;

class FeedbackController extends BaseController {

    public function index() {
        $amuse_mod = M('users_feedback');
		$where = '1=1';
		$keywords = trim(I('keywords'));
        $keywords && $where.=" and content like '%$keywords%' ";
		$p = empty($_REQUEST['p']) ? 1 : $_REQUEST['p'];
        $size = empty($_REQUEST['size']) ? 20 : $_REQUEST['size'];
		$count = $amuse_mod->where($where)->count();
        $pager = new \Think\Page($count, $size);
        $page = $pager->show();
		 $keywords && $w="a.contents like '%$keywords%' ";
		$amuse_list = $amuse_mod->alias('as a')->join(C('DB_PREFIX').'users as b on a.user_id=b.id')->where($w)->field('a.id,a.add_time,a.contents,b.user_name,b.phone,b.head_picture,a.images')->order('a.id desc')->page("$p,$size")->select();
		foreach((array)$amuse_list as $k=>$v){
			if($v['images']){
				$img = '';
				$all_img = explode(',',$v['images']);
				foreach((array)$all_img as $kk=>$vv){
					$img.= '<a target="_blank" href="'.__ROOT__.'/Public/upload/user/'.$vv.'"><img style="margin-right:10px;" src="'.__ROOT__.'/Public/upload/user/'.$vv.'" width="34" height="34"></a>';
				}
				$amuse_list[$k]['images'] = $img;
			}
		}
		$this->assign('list', $amuse_list);
		$this->assign('page', $page);
		$this->display();	
    }
	
	public function comment_img(){
		$id = I('id');
		if($id){
			$amuse_img_mod = M('users_feedback');
			$result = $amuse_img_mod->where(array('id'=>$id))->delete();
			if($result){
				exit(json_encode(array('code'=>200)));	
			}else{
				exit(json_encode(array('code'=>100)));	
			}
		}
	}

}
